﻿@model  List<Category>
@using Models
@{
    var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
    FormsAuthenticationTicket auth = null;
    if (cookie != null)
    {
        auth = FormsAuthentication.Decrypt(cookie.Value);

        ViewBag.auth = auth;
    }
    
    ViewBag.Title = "Categories";
}
<div style="float: left; height: 70px"><a href="/admin/index" ><img src="/Content/images/back.png" /></a></div>
<div style="margin-left: 80px; text-align: center; width: 100px"><a href="/admin/AddCategory" ><img src="/content/images/category_add.png" alt="Add category" /><br />Add category</a></div>

<h2>Categories</h2>
 @Html.Partial("_openDialog")
<table id="table_admin">
 @if(Model != null)
        {
    <tr>
        <td>
            @Html.ActionLink("ID","Categories","Admin", new {page=ViewBag.pager.CurrentPage,orderBy="id"},null)
        </td>
        <td>
            @Html.ActionLink("Name","Categories","Admin", new {page=ViewBag.pager.CurrentPage,orderBy="name"},null)
        </td>
        <td>
           Description
        </td>
        <td>
            Action button 
        </td>
    </tr>
       
        for(int i = ViewBag.pager.StartIndex-1; i < ViewBag.pager.EndIndex; i++)
        {
            Category cat = Model[i];
            
            <tr>
                <td>
                    @cat.Id    
                </td>
                <th>
                    @cat.Name
                </th>
                <td>
                    @cat.Description
                </td>
                <th>
                     <a href="/Admin/UpdateCategory/@cat.Id"><img src="/content/images/Refresh.png" alt="Update" /></a>

                    
                    @if (auth.UserData == "1")
                    {
                        <a href="/admin/deleteCategory/@cat.Id" onmousedown="return openDialog(@cat.Id,'/Admin/DeleteCategory')" ><img src="/content/images/Delete.png" alt="Delete" /></a>
                    }
                </th>
            </tr>
        }
        }
</table>